﻿using Gear.ToolKits.Helper;
using Gear.Web.Api.DynamicDataApi.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gear.Web.Api.DynamicDataApi.Macro
{
    /// <summary>
    /// 分页条件宏
    /// </summary>
    public static class PageMacro
    {
        public static readonly string Pageword = "paging";// 分页标识关键字

        public static string PageTrans(string _content, Dictionary<string, object> param)
        {
            StringBuilder sb = new(_content);

            param.TryGetValue(Pageword, out object Value); if (Value == null) return _content;

            var PageMod = JsonHelper.DeserializeJSON<Pages>(Value.ToString());

            if (Pageword != null) sb.Append($" limit {(PageMod.PageIndex-1)* PageMod.PageSize},{PageMod.PageSize}");

            return sb.ToString();
        }
    }
}
